package LeetCode.month02.day51;

import LeetCode.month02.day50.ListNode;

public class No19 {
    int count = 0;
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode newhead = new ListNode(0,head);
        newhead= getNode(newhead, n);
        return newhead.next;
    }
    public ListNode getNode(ListNode head,int target){
        if(head.next==null) {
            return head;
        }
        ListNode node = getNode(head.next, target);
        count++;
        if(count==target) head.next = node.next;
        return head;
    }
}
